package bist.believeinstep.administrator.view;

import bist.believeinstep.logic.ArticleService;

import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.util.HierarchicalContainer;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.Tree;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.event.Action;
import elemental.events.MouseEvent.Button;

public class MenuView extends HorizontalLayout implements Property.ValueChangeListener, Action.Handler{
	
	private Tree rootMenu;
	 private static final String[][] hardware = { //
         { "Desktops", "Dell OptiPlex GX240", "Dell OptiPlex GX260",
                 "Dell OptiPlex GX280" },
         { "Monitors", "Benq T190HD", "Benq T220HD", "Benq T240HD" },
         { "Laptops", "IBM ThinkPad T40", "IBM ThinkPad T43",
                 "IBM ThinkPad T60" } };
	
	public MenuView() {
		initialize();
	}
	
	public void initialize() {
		this.setSizeFull();
		this.setSpacing(true);
		initMenu();
	}
	
	public void initMenu() {
		rootMenu = new Tree("BIST Management");
		rootMenu.setImmediate(true);
		rootMenu.addListener(this);
		rootMenu.addActionHandler(this);
		rootMenu.setItemCaptionPropertyId("WWWWW");
		rootMenu.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
		rootMenu.setContainerDataSource(getContainer());
		addComponent(rootMenu);
		// Expand whole tree
        for (Object id : rootMenu.rootItemIds()) {
        	rootMenu.expandItemsRecursively(id);
        }
        
        
	}

	@SuppressWarnings("unchecked")
	public static HierarchicalContainer getContainer() {
		Item item = null;
		int itemId = 0;
		HierarchicalContainer hwContainer = new HierarchicalContainer();
		hwContainer.addContainerProperty("BLU1", String.class, null);
		for (int i = 0; i < hardware.length; i++) {
			item = hwContainer.addItem(itemId);
			item.getItemProperty("BLU1").setValue(hardware[i][0]);
			hwContainer.setChildrenAllowed(itemId, true);
			itemId ++;
			for (int j = 1; j < hardware[i].length; j++) {
//				if (j == 1) {
//					
//				}
				item = hwContainer.addItem(itemId);
				item.getItemProperty("BLU1").setValue(hardware[i][j]);
				hwContainer.setParent(itemId, itemId - j);
				hwContainer.setChildrenAllowed(itemId, false);
				
				itemId ++;
			}
		}
		return hwContainer;
	}
	
	
	@Override
	public Action[] getActions(Object target, Object sender) {
		
		return null;
	}

	@Override
	public void handleAction(Action action, Object sender, Object target) {
		
		
	}

	@Override
	public void valueChange(ValueChangeEvent event) {
		// TODO Auto-generated method stub
		
	}
}
